<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
</head>
<body>
    <div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div>
                <header style="height: 100%">
                    <div align="left">
	                    <table style="width: 100%">
	                   		<tr>
	                   			<td>
		                   			<form class="form-inline" id="searchForm" onsubmit="return false">
										<div class="form-group" style="width:95%;">
											流程业务类型：
											<select id="verifyType">
												<option value="">全部</option>
											</select>
											关键字：
											<input id="keys" type="search" class="form-control" placeholder="标题或者通知内容">
											阅读状态：
											<select id="status">
												<option value="">全部</option>
												<option value="0">未读</option>
												<option value="1">已读</option>
											</select>
											<button id="searchRest" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe9aa;</i>重置</button>
											<button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索</button>
										</div>
									</form>
	                   			</td>
	                   			<td align="right">
	                   				<button class="layui-btn layui-btn-sm" onclick="location.href='addFlow.html'">
                                      <i class="layui-icon">&#xe608;</i> 添加流程
                                    </button>
	                   			</td> 
	                   		</tr> 
	                    </table>
					</div>
                </header>
                
                <div>
                    <div class="widget-body no-padding">
                        <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                            <thead>
                                <tr>
                                </tr>                       
                                <tr>
									<th>任务节点</th>
									<th>流程名称</th>
									<th>发送人</th>
									<th>发送时间</th>
									<th>阅读状态</th>
									<th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript" src="../../js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript">
var pers = checkPermission();

var example;
function init(){
	example = 
    	$('#dt-table').DataTable({
        	"searching": false,
        	"processing": false,
        	"serverSide" : true,
        	"ordering" : false,
        	"language": {
                "url": urlRootPrefix + "/js/plugin/datatables/Chinese.lang"
            },
        	"ajax": {
        		"url" : urlRootPrefix + "/msgNoticeReads",
        		"type":"get",
        		"data":function(d){
        			d.selectTypeId = 4;
    				d.verifyType = $("#verifyType").val();
    				d.keywords = $("#keywords").val();
    				d.status = $("#status").val();
    			},
    			"dataSrc" : function(data) {
  				  //自定义错误拦截
   		          if(!data.success && !isNotBlank(data.recordsTotal)){
   		           	layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
   					return [];
   				  }
   		          return data.data;
    			} 
        	},
        	"dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",	
            "columns": [
				{"data" : "title", "defaultContent" : ""},
				{"data" : "flowName", "defaultContent" : ""},
				{"data" : "pushUserName", "defaultContent" : ""},
				{"data" : "pushTime", "defaultContent" : ""},
				{"data" : "statusName", "defaultContent" : "",
			        "render": function (data, type, row) {
			        	if("未读" == data)
          		       		return "<span style='color:red'>"+data+"</span>"
          		       	else
          		       		return "<span style='color:green'>"+data+"</span>"
              	    }		
				},
				{"data" : "href", 
					"defaultContent": "",
					"orderable":false,
			        "render": function (data, type, row) {
           		         var go = urlRootPrefix + "/"+data+"&readId="+row['readId']+"&type=0"; 
                         return "<button class='layui-btn layui-btn-xs' title='阅读详情' onclick='openIframeDetails(\""+ row['readId'] + "\",\""+ go + "\",\""+ row['content'] + "\")'><i class='layui-icon'>&#xe615;</i></button>";
               	    }		
				},
                
            ],
           "order": [[ 0, "asc" ]]
        } );
}

layui.use('layer', function(){
    var layer = layui.layer;
});

function del(id){
	layer.confirm('确定要删除吗？', {
        btn : [ '确定', '取消' ]
    }, function() {
    	$.ajax({
            type : 'delete',
            url : urlRootPrefix + '/flows/'+id,
            success : function(data) {
            	if(!data.success){
					layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					$("button[type='submit']").removeAttr("disabled");
					return;
				}
                example.ajax.reload();
                layer.msg("删除成功");
            }
        });
        
        layer.close(1);
    });
}
function getFlowTaskType(){
   	$.ajax({
           type : 'get',
           url : urlRootPrefix + '/flowTaskTypes/listVo',
           success : function(data) {
	           	if(!data.success){
	           		layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
					return;
				}
	           	var data = data.data;
	           	var typeHtml = "";
	           	for(var i=0;i<data.length;i++){
	           		typeHtml += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
	           	}
	           	$("#verifyType").append(typeHtml);
           }
       });
}
$("#searchBt").click(function(){
	example.ajax.reload();
});
$("#searchRest").click(function(){
	$('#searchForm')[0].reset();
	$("#followOrgIds").attr("followOrgIds","");
});

getFlowTaskType();
init();
window.parent.showUnreadNotice();
function openIframeDetails(readId,go,content) {
	$.ajax({
        type : 'get',
        url : urlRootPrefix + '/msgNoticeReads/read/'+readId,
        success : function(data) {
           	if(!data.success){
           		layer.msg(data.msg, {shift: -1, time: 3000}, function(){});
				return;
			}
           	window.parent.showUnreadNotice();
           	layer.open({
        		type : 1,
        		title : "阅读详情",
        		shadeClose : false,
        		shade : 0.8,
        		maxmin : false, //开启最大化最小化按钮
        		area : [ '500px' ],
        		content : "<div style='display:flex;padding:20px;'><p>"+content+"</p></div>",
        		btn : [ '审批流程', '审批记录', '前往查看' ],
        		btn1 : function(index, layero) {
        			showMaxWindow(urlRootPrefix + "/pages/flowDesign/hccflow/page/design.html?flowId="+readId+"&status=2","审批流程走势图");
        		},
        		btn2 : function(index, layero) {
        			showMaxWindow(urlRootPrefix + "/pages/common/verifyLogList.html?readId="+readId,"审批记录");
        			return false;
        		},
        		btn3 : function(index, layero) {
        			showMaxWindow(go,"任务详情");
        			return false;
        		},
        		cancel : function(index, layero) {
        			example.ajax.reload();
        			layer.close(index);
        		}
        	});
        }
    });
	
}
</script>
